﻿//统一文件为utf-8编码编译
#pragma execution_character_set("utf-8")
///////////////////////////////////////////////////////////////////////////
// 文件名:     mainwindow.cpp
// 描述:
// 作者:      颜磊
// 创建工程：   AudioComment
// 创建时间:   2024-06-25 10:13
///////////////////////////////////////////////////////////////////////////
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include "disposewidget.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QFile file(QCoreApplication::applicationDirPath()+"/StyleSheet/BlackAndBlue.qss");
    if(file.open(QFile::ReadOnly)){
        //QApplication::setStyle(file.readAll());
        setStyleSheet(file.readAll());
        file.close();
    }
    connect(ui->fileListWidget,&FileListWidget::signal_openDisposeWidget,this,&MainWindow::slot_openDisposeWidget);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::slot_openDisposeWidget(QString path)
{
    bool exists = false;
    for (int i=0;i<ui->tabWidget->count();i++) {
        DisposeWidget *disposeWidget = (DisposeWidget *)ui->tabWidget->widget(i);
        if(disposeWidget->getAudioFilePath() == path){
            exists = true;
            ui->tabWidget->setCurrentIndex(i);
            break;
        }
    }
    if(!exists){
        QFileInfo fileInfo(path);
        DisposeWidget *disposeWidget = new DisposeWidget(path);
        ui->tabWidget->addTab(disposeWidget,fileInfo.fileName());
        ui->tabWidget->setCurrentIndex(ui->tabWidget->count()-1);
    }
}


void MainWindow::on_tabWidget_tabCloseRequested(int index)
{
    DisposeWidget *disposeWidget = (DisposeWidget *)ui->tabWidget->widget(index);
    ui->tabWidget->removeTab(index);
    delete disposeWidget;
}
